from core.support import set_cutscene
from core.item import Item
from core.action import Action

class BottleCap(Item):
    def __init__(self):
        Item.__init__(self, "bottlecap")    # do basic initialization for every item
        #self.is_used = False
        
        # build list of actions
        self.add_action(ThrowBottleCap)
    
    def get_description(self):
            return "Sam Adams Bottle Cap"

# define actions for this item

class ThrowBottleCap(Action):
    def __init__(self):
        Action.__init__(self, "throw_bottlecap")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Throw Bottle Cap"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in hallway. add cutscene
    def do_action(self,game,room,request):
        if room.get_id() == 'hallway':
            if room.ken_talk == False:
                set_cutscene("You have already distracted Ken. Don't be mean dude !!")
                #self.item.is_used = True
            elif room.solution == 2:
                set_cutscene("You manage to flip the bottle cap into into Ken's eyes")
                room.ken_talk = False
                room.ken_distracted = "bottlecap"
                #self.item.is_used = True
            else:
                set_cutscene("You threw the bottle cap but did not distract Ken")
                #room.ken_talk = True
                #self.item.is_used = True
            
            item = game.player.pop_item("bottlecap")
            item.do_item_dropped(game,room,request)
            room.add_item(item)
            
        elif room.get_id() == 'cornwalls':         
            set_cutscene("You threw the Sam Adams bottle cap at MC. He smirks and points to his glass of Guinness.")
            item = game.player.pop_item("bottlecap")
            item.do_item_dropped(game,room,request)
            room.add_item(item)
            
        else:
            set_cutscene("You threw the Bottle Cap but nothing happened.")
            item = game.player.pop_item("bottlecap")
            item.do_item_dropped(game,room,request)
            room.add_item(item)
        return
    
    #def is_enabled(self):
        #if self.item.is_used == True:
            #return False
        #else:
            #return True